package com.ruoyi.goodsDetail.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goodsDetail.domain.OrderGoodsDetail;
import com.ruoyi.goodsDetail.service.IOrderGoodsDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品订单详情信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/ruoyi/goodsDetail")
public class OrderGoodsDetailController extends BaseController
{
    @Autowired
    private IOrderGoodsDetailService orderGoodsDetailService;

    /**
     * 查询商品订单详情信息列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderGoodsDetail orderGoodsDetail)
    {
        startPage();
        List<OrderGoodsDetail> list = orderGoodsDetailService.selectOrderGoodsDetailList(orderGoodsDetail);
        return getDataTable(list);
    }

    /**
     * 导出商品订单详情信息列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:export')")
    @Log(title = "商品订单详情信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderGoodsDetail orderGoodsDetail)
    {
        List<OrderGoodsDetail> list = orderGoodsDetailService.selectOrderGoodsDetailList(orderGoodsDetail);
        ExcelUtil<OrderGoodsDetail> util = new ExcelUtil<OrderGoodsDetail>(OrderGoodsDetail.class);
        util.exportExcel(response, list, "商品订单详情信息数据");
    }

    /**
     * 获取商品订单详情信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(orderGoodsDetailService.selectOrderGoodsDetailByDetailId(detailId));
    }

    /**
     * 根据商品订单id获取商品订单详情信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:query')")
    @ApiOperation("根据商品订单id获取商品订单详情信息详细信息测试接口")
    @GetMapping(value = "/getGoodsDetailByOrderId/{orderId}")
    public AjaxResult getGoodsDetailByOrderId(@PathVariable("orderId") Long orderId)
    {
        return success(orderGoodsDetailService.selectOrderGoodsDetailByOrderId(orderId));
    }

    /**
     * 新增商品订单详情信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:add')")
    @Log(title = "商品订单详情信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderGoodsDetail orderGoodsDetail)
    {
        return toAjax(orderGoodsDetailService.insertOrderGoodsDetail(orderGoodsDetail));
    }

    /**
     * 修改商品订单详情信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:edit')")
    @Log(title = "商品订单详情信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderGoodsDetail orderGoodsDetail)
    {
        return toAjax(orderGoodsDetailService.updateOrderGoodsDetail(orderGoodsDetail));
    }

    /**
     * 删除商品订单详情信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:goodsDetail:remove')")
    @Log(title = "商品订单详情信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(orderGoodsDetailService.deleteOrderGoodsDetailByDetailIds(detailIds));
    }
}
